#ifndef MEDICALRECORDWIDGET_H
#define MEDICALRECORDWIDGET_H

#include <QWidget>
#include <QJsonObject>
#include <QDateTime>
#include "../../../Common/models.h"
#include "../../../Common/protocol.h"

namespace Ui {
class MedicalRecordWidget;
}

class MedicalRecordWidget : public QWidget {
    Q_OBJECT
    
public:
    explicit MedicalRecordWidget(const Doctor& doctor, QWidget *parent = nullptr);
    explicit MedicalRecordWidget(const Doctor& doctor, const Patient& patient, QWidget *parent = nullptr);
    explicit MedicalRecordWidget(const Doctor& doctor, const Patient& patient, int appointmentId, const QDateTime& appointmentTime, QWidget *parent = nullptr);
    ~MedicalRecordWidget();
    
signals:
    void recordCreated();  // 病历创建成功信号
    void backToPatientDetail();  // 返回患者详情信号
    
private slots:
    void on_saveButton_clicked();
    void on_clearButton_clicked();
    void on_backButton_clicked();  // 返回按钮点击槽函数
    void onMessageReceived(MessageType type, const QJsonObject& data);
    
private:
    void setupPatientInfo(const Patient& patient);
    
    Ui::MedicalRecordWidget *ui;
    Doctor m_doctor;
    bool m_hasPatient;
    int m_appointmentId;         // 预约ID，用于保存到病历
    QDateTime m_appointmentTime;  // 预约时间，用于验证
};

#endif // MEDICALRECORDWIDGET_H

